using System;
using System.Windows;

namespace LaplaceMeshDeformer
{
    /// <summary>
    /// 区域缩放变形对话框
    /// </summary>
    public partial class ScaleDeformWindow : Window
    {
        public int CenterIndex { get; private set; }
        public double Radius { get; private set; }
        public double ScaleFactor { get; private set; }

        public ScaleDeformWindow(int maxVertexIndex)
        {
            InitializeComponent();
            
            // 默认值
            CenterIndex = 0;
            Radius = 1.0;
            ScaleFactor = 1.2;
            
            // 设置输入框默认值
            txtCenterIndex.Text = "0";
            txtRadius.Text = "1.0";
            txtScaleFactor.Text = "1.2";
            
            // 设置ToolTip
            txtCenterIndex.ToolTip = $"有效范围: 0-{maxVertexIndex}";
        }

        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            // 验证输入
            if (!int.TryParse(txtCenterIndex.Text, out int centerIndex) ||
                !double.TryParse(txtRadius.Text, out double radius) ||
                !double.TryParse(txtScaleFactor.Text, out double scaleFactor))
            {
                MessageBox.Show("请输入有效的数值！", "输入错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            
            if (radius <= 0)
            {
                MessageBox.Show("半径必须大于0！", "输入错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            
            if (scaleFactor <= 0)
            {
                MessageBox.Show("缩放因子必须大于0！", "输入错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            
            CenterIndex = centerIndex;
            Radius = radius;
            ScaleFactor = scaleFactor;
            
            DialogResult = true;
            Close();
        }
    }
} 